import info.gridworld.grid.Location;

import java.util.ArrayList;


/**
 * A set of Cell Patterns that can be added to the World. Each pattern is implemented using an ArrayList of Locations into which
 * Cells will be added. When inserting a Pattern, give the coordinates of the top-left Cell (even if it's empty) of the Pattern.
 * 
 * <p>To insert a Pattern into the World, use the World's <code>addPattern</code> method:
 * <br><code>world.addPattern(Pattern.gliderGun(new Location(4, 4)));</code>
 * <br>or
 * <br><code>world.addPattern(Pattern.gliderGun(4, 4));</code>
 * 
 * <p>The code for all Patterns are created by Drew Gallagher unless otherwise noted in the Javadoc.
 * 
 * @author Drew Gallagher
 * @version 1.0
 * @see LifeWorld.#addPattern(java.util.ArrayList)
 */
public class Patterns {

	/**
	 * Glider Gun that accepts a Location object.
	 * 
	 * @param loc Top-Left location.
	 * @return ArrayList of Locations.
	 * @since 1.0
	 * @see #gliderGun(int, int)
	 */
	public static ArrayList<Location> gliderGun(Location loc) {
		return gliderGun(loc.getRow(), loc.getCol());
	} // End ArrayList<Location> gliderGun
	
	/**
	 * A Glider Gun.
	 * 
	 * <p>Wikipedia:
	 * <br>In a cellular automaton, a gun is a pattern of which the main part repeats periodically, like an oscillator,
	 * and which also periodically emits spaceships. There are then two periods that may be considered. There is the
	 * period of the spaceship output and the period of the gun itself, which is necessarily a multiple of the spaceship
	 * output's period. A gun whose period is larger than the period of the output is a pseudoperiod gun.
	 * 
	 * <p>This Pattern implements Gosper's Glider Gun, the smallest currently known.
	 * 
	 * @param row Top-Left Location row.
	 * @param col Top-Left Location column.
	 * @return ArrayList of Locations.
	 * @since 1.0
	 */
	public static ArrayList<Location> gliderGun(int row, int col) {
		ArrayList<Location> locs = new ArrayList<Location>();
		locs.add(new Location(row, col + 24));
		locs.add(new Location(row + 1, col + 22));
		locs.add(new Location(row + 1, col + 24));
		locs.add(new Location(row + 2, col + 12));
		locs.add(new Location(row + 2, col + 13));
		locs.add(new Location(row + 2, col + 20));
		locs.add(new Location(row + 2, col + 21));
		locs.add(new Location(row + 2, col + 34));
		locs.add(new Location(row + 2, col + 35));
		locs.add(new Location(row + 3, col + 11));
		locs.add(new Location(row + 3, col + 15));
		locs.add(new Location(row + 3, col + 20));
		locs.add(new Location(row + 3, col + 21));
		locs.add(new Location(row + 3, col + 34));
		locs.add(new Location(row + 3, col + 35));
		locs.add(new Location(row + 4, col + 0));
		locs.add(new Location(row + 4, col + 1));
		locs.add(new Location(row + 4, col + 10));
		locs.add(new Location(row + 4, col + 16));
		locs.add(new Location(row + 4, col + 20));
		locs.add(new Location(row + 4, col + 21));
		locs.add(new Location(row + 5, col + 0));
		locs.add(new Location(row + 5, col + 1));
		locs.add(new Location(row + 5, col + 10));
		locs.add(new Location(row + 5, col + 14));
		locs.add(new Location(row + 5, col + 16));
		locs.add(new Location(row + 5, col + 17));
		locs.add(new Location(row + 5, col + 22));
		locs.add(new Location(row + 5, col + 24));
		locs.add(new Location(row + 6, col + 10));
		locs.add(new Location(row + 6, col + 16));
		locs.add(new Location(row + 6, col + 24));
		locs.add(new Location(row + 7, col + 11));
		locs.add(new Location(row + 7, col + 15));
		locs.add(new Location(row + 8, col + 12));
		locs.add(new Location(row + 8, col + 13));
		return locs;
	} // End ArrayList<Location> gliderGun
	
} // End class Patterns
